<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="../StaticFiles/element-plus-2.9.1/index.css" rel="stylesheet">
  <link href="../StaticFiles/nprogress/nprogress.min.css" rel="stylesheet">
  <link href="../styles/vue-page-common.css" rel="stylesheet">
  <script src="../Scripts/pollyfills/Array.prototype.flat.js"></script>
  <script src="../Scripts/pollyfills/ResizeObserver.js"></script>
  <script src="../StaticFiles/vue3/vue.global.prod.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/index.full.min.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/icons-vue.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/zh-cn.min.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>重点件号批次加工进度查询报表</title>
  <style>
    .el-table--large .cell {
      padding: 0 10px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <vue3-report-header :title="dataObj.queryInfo.tofactoryname+'重点件号批次加工进度查询报表'"></vue3-report-header>
    <div style="padding: 10px;" @keyup.enter="getData">
      <el-form :inline="true" :model="dataObj.queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="主制分厂:">
          <el-select style="width: 160px;" v-model="dataObj.queryInfo.factoryname" placeholder="请选择主制分厂" clearable
            filterable>
            <el-option v-for="f in dataObj.factoryList" :key="f.factoryname" :label="f.factoryname"
              :value="f.factoryname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="零件图号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.containername" placeholder="请输入流水卡号"
            :trigger-on-focus="false" style="width:280px;" :fetch-suggestions="searchContainerAsync"
            :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="工序名称:">
          <el-input v-model.trim="dataObj.queryInfo.workflowstepname" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item label="接收时间:">
          <el-date-picker v-model="dataObj.queryInfo.receivedate" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD" :shortcuts="dataObj.shortcuts">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="数据来源:">
          <el-select v-model="dataObj.queryInfo.sourcetype" placeholder="请选择" clearable filterable
            style="width: 100px;">
            <el-option :key="1" :label="'MES'" :value="1"></el-option>
            <el-option :key="2" :label="'其他'" :value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="完成状态:">
          <el-select v-model="dataObj.queryInfo.status" placeholder="请选择" clearable filterable style="width: 100px;">
            <el-option :key="'已完成'" :label="'已完成'" :value="'已完成'"></el-option>
            <el-option :key="'未完成'" :label="'未完成'" :value="'未完成'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" :icon="'Search'" size="default" @click="getData">查询</el-button>
          <el-button type="primary" :icon="'Download'" size="default" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table :data="dataObj.dataList" stripe border show-overflow-tooltip v-loading.fullscreen.lock="dataObj.loading"
        :element-loading-text="dataObj.loadingText" element-loading-background="rgba(0,0,0,0.8)">
        <el-table-column type="index" width="60"></el-table-column>
        <el-table-column prop="sourcetype" label="数据来源" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="factoryname" label="主制分厂" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column prop="containername" label="流水卡号" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column prop="qty" label="数量" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productname" label="零件号" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productdescription" label="零件名称" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflowstepname" label="工序" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="currentprocess" label="加工进度" show-overflow-tooltip></el-table-column>
        <el-table-column prop="receivedate" label="接收时间" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="needfinishdate" label="要求完成时间" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="finishdate" label="完成时间" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="createuser" label="创建人" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="createdate" label="创建时间" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="status" label="完成状态" width="80" show-overflow-tooltip>
          <template #default="scope">
            <el-tag :type="scope.row.status === '已完成' ? 'success' : 'danger'">{{scope.row.status}}</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="dataObj.currentPage" :page-sizes="[dataObj.pageSize,20,50]" :page-size="dataObj.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="dataObj.total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { exportExcel, getFactory, fetchSuggestion, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/vue3DateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue3ReportHeader from '../Scripts/components/Vue3ReportHeader.js';
    const { createApp, reactive, ref, onMounted, watch } = Vue
    const { ElMessage } = ElementPlus
    const App = {
      setup() {
        const dataObj = reactive({
          loading: false,
          loadingText: '数据加载中...',
          currentPage: 1,// 当前页
          pageSize: 12, // 每页显示条数
          total: 0,
          factoryList: [],
          queryInfo: {
            factoryname: '',
            productname: '',
            containername: '',
            workflowstepname: '',
            receivedate: '',
            sourcetype: '',
            status: '',
            tofactoryname: ''
          },
          dataList: [],
          shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth]
        })

        function searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        }

        function searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        }

        // 查询分厂名称
        async function getFactoryInfo() {
          const { data: res } = await axios({
            url: '../handler/report/CommonActionHandle.ashx?actions=getFactoryInfo',
            method: 'post',
            data: { type: 'getFactoryInfo', factoryid: Decrypt(getParams('factoryid')), isMapping: '是' }
          })
          const { factoryid, factoryname } = res.data[0];
          dataObj.queryInfo.tofactoryname = factoryname;
          document.title = factoryname + '重点件号批次加工进度查询报表';
        };

        // 查询数据
        async function getData() {
          dataObj.loading = true;
          dataObj.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios({
            url: '../handler/report/RbFocusContainerProcessReport.ashx?actions=getData',
            method: 'post',
            data: {
              ...dataObj.queryInfo,
              currentPage: dataObj.currentPage,
              pageSize: dataObj.pageSize,
              type: 'getData'
            }
          })
          dataObj.loading = false
          if (meta.status === 500) {
            return ElMessage.error(meta.msg);
          }
          dataObj.dataList = data;
          dataObj.total = total;
        };

        // 导出excel
        function getExportExcel() {
          const config = {
            url: '../handler/report/RbFocusContainerProcessReport.ashx?actions=exportExcel',
            data: { ...dataObj.queryInfo }
          }
          exportExcel(config, dataObj, ElMessage);
        };

        function handleCurrentChange(newPage) {
          dataObj.currentPage = newPage;
          getData();
        };

        function handleSizeChange(newSize) {
          dataObj.pageSize = newSize;
          getData();
        };

        onMounted(() => {
          getFactory(dataObj);
          getFactoryInfo();
        })

        watch(() => dataObj.queryInfo, () => {
          dataObj.currentPage = 1;
        }, { deep: true })

        return {
          dataObj,
          getData,
          getExportExcel,
          handleCurrentChange,
          handleSizeChange,
          searchContainerAsync,
          searchProductAsync,
          splitDate
        }
      }
    };

    const app = createApp(App);
    app.use(ElementPlus, {
      locale: ElementPlusLocaleZhCn,
      size: 'large'
    });
    // 注册所有icon
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component)
    }
    app.component('vue3-report-header', Vue3ReportHeader);
    app.mount('#app');
  </script>
</body>

</html>